package gui;
import java.awt.BorderLayout;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.WindowConstants;
import org.jdesktop.application.Application;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CreateUser extends javax.swing.JPanel {
	
	private JFrame 	frame;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JTextField userField;
	private JButton cancelButton;
	private JButton signUpB;
	private JTextField passField;
	private JLabel jLabel1;
	private model.search.System sistem;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	
	
	public CreateUser(model.search.System sis) {
		super();
		this.sistem = sis;
		initGUI();
	}
	
	private void initGUI() {
		frame = new JFrame();
		frame.getContentPane().add(this, BorderLayout.CENTER);
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setSize(350, 250);
		frame.setTitle("Create a new user");
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		try {
			this.setPreferredSize(new java.awt.Dimension(217, 207));
			this.setLayout(null);
			{
				jLabel1 = new JLabel();
				this.add(jLabel1);
				jLabel1.setBounds(125, 18, 148, 17);
				jLabel1.setName("jLabel1");
			}
			{
				jLabel3 = new JLabel();
				this.add(jLabel3);
				jLabel3.setBounds(47, 119, 74, 14);
				jLabel3.setName("jLabel3");
			}
			{
				userField = new JTextField();
				this.add(userField);
				userField.setBounds(152, 66, 93, 21);
			}
			{
				passField = new JPasswordField();
				this.add(passField);
				passField.setBounds(152, 112, 93, 21);
			}
			{
				signUpB = new JButton();
				this.add(signUpB);
				signUpB.setBounds(137, 156, 118, 21);
				signUpB.setName("signUpB");
				signUpB.addActionListener(new SignUpAct());
			}
			{
				jLabel2 = new JLabel();
				this.add(jLabel2);
				jLabel2.setBounds(47, 73, 74, 14);
				jLabel2.setName("jLabel2");
			}
			{
				cancelButton = new JButton();
				this.add(cancelButton);
				cancelButton.setBounds(155, 188, 81, 21);
				cancelButton.setName("cancelButton");
				cancelButton.addActionListener(new CancelClass(frame));
			}
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class SignUpAct implements ActionListener{
		
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(userField.getText().equals("") || passField.getText().equals("")){
				new EmptyFieldPanel();
			}
			else{
				sistem.getUsers().put(userField.getText(), passField.getText());
				frame.dispose();
			}
		}
		
	}

}
